package cn.com.czpb.client.module.news.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import cn.com.czpb.client.R;
import cn.com.czpb.client.model.news.HotSearchBean;

import java.util.ArrayList;
import java.util.List;

/**
 * @author fyales
 * @since 8/26/15.
 */
public class TagBaseAdapter extends BaseAdapter {

    private Context mContext;
    private List<HotSearchBean> mList;

    public TagBaseAdapter(Context context) {
        mList =new ArrayList<>();
        mContext = context;
    }
    public void addData( List<HotSearchBean> list){

        mList =list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public HotSearchBean getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_search_history, null);
            holder = new ViewHolder();
            holder.tagBtn = convertView.findViewById(R.id.tv_content_id);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder)convertView.getTag();
        }
        final String text = getItem(position).getContent();
        holder.tagBtn.setText(text);
        return convertView;
    }

    static class ViewHolder {
        TextView tagBtn;
    }
}
